/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Controlador.Manejadores;


import Controlador.RequestHandler;
import Persistencia.DAOFactory;
import Persistencia.Entidades.Responsable;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 *
 * @author zeta
 */
public class ValidarUsuarios implements RequestHandler{
    Responsable resp;
    DAOFactory DAO;
    public ValidarUsuarios() {
    DAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE);
    }

    public String handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

            resp = DAO.getResponsableDAO().getResponsable(request.getParameter("username"));
            String pass = request.getParameter("password");
            String usu = request.getParameter("username");

          if(resp == null ){
               request.setAttribute("mensaje", "Usuario o Contraseña no validas");
               return "/login.jsp";
          }else if(pass.equals(resp.getContraseña()) && resp.getNombreUsuario().equals(usu)){
                 request.getSession().setAttribute("usuario", resp);
             return "/index.jsp";

          }
          else{
           request.setAttribute("mensaje", "Usuario o Contraseña no validas");
                 return "/login.jsp";
          }
      }



    

}
